package com.mao.wx.demo.util;

import java.security.MessageDigest;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
@Qualifier("wxEncryptUtil")
public class WxEncryptUtil {

	public static final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
			'f' };

	public WxEncryptUtil() {
	}

	/**
	 * 使用Sha1加密算法获得密文
	 * 
	 * @param content
	 * @return
	 */
	public String getSha1(String content) throws Exception {
		if (content == null || content.length() == 0) {
			throw new RuntimeException("Bad arguments: getSha1(@NOTNULL String content )");
		}
		try {
			MessageDigest md = MessageDigest.getInstance("SHA1");
			md.update(content.getBytes("utf-8"));
			byte[] signature = md.digest();
			int j = signature.length;
			char[] buf = new char[j * 2];
			int k = 0;
			for (int i = 0; i < j; i++) {
				byte byte0 = signature[i];
				buf[k++] = hexDigits[byte0 >>> 4 & 0xf];
				buf[k++] = hexDigits[byte0 & 0xf];
			}
			return new String(buf);
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage());
		}
	}

	/**
	 * 加密算法枚举
	 * @author 54353
	 *
	 */
	public static enum WxEncryptAlgorim {
		
	};
	
	
}

